#ifndef GA_BOARD_H
#define GA_BOARD_H


#define FLAG_ON   1
#define FLAG_OFF  0

class GAPiece
{
	public:
	GAPiece() { }
	~GAPiece(){ }
	public:
	GAPiece& operator=(GAPiece& op)
	{
		nRed = op.nRed;
		nGreen = op.nGreen;
		nBlue = op.nBlue;
		nFlags = op.nFlags;
	}
	public:
	int nRed, nGreen, nBlue;
	int nFlags;
};



class GABoard
{
	private:
	int m_nWidth, m_nHeight;
	GAPiece *m_pBoard;

	public:
	int GetWidth() { return m_nWidth; }
	int GetHeight() { return m_nHeight; }
	public:
	GABoard(int nWidth, int nHeight);
	~GABoard();

	GAPiece& PieceAt(int x, int y);

	void SetPiece(int x, int y, int r = 0, int g = 0, int b = 0) 
	{ 
		m_pBoard[y * m_nWidth + x].nFlags = FLAG_ON;
		m_pBoard[y * m_nWidth + x].nRed = r;
		m_pBoard[y * m_nWidth + x].nGreen = g;
		m_pBoard[y * m_nWidth + x].nBlue = b;

	}
	void RemovePiece(int x, int y, int r = 0, int g = 0,  int b = 0)
	{
		m_pBoard[y * m_nWidth + x].nFlags = FLAG_OFF;
		m_pBoard[y * m_nWidth + x].nRed = r;
		m_pBoard[y * m_nWidth + x].nGreen = g;
		m_pBoard[y * m_nWidth + x].nBlue = b;


	}

	int IsPieceOn(int x, int y)
	{
		return m_pBoard[y * m_nWidth + x].nFlags == FLAG_ON;
	}

	int ApplyGravity(void);
	void Clear(void);
	void RemoveOneLine(int y);

};


#endif

